package com.ict.controller;


import com.ict.api.dto.IctOrderDTO;
import com.ict.api.dto.IctOrderPayDTO;
import com.ict.api.result.ApiResponse;
import com.ict.api.vo.IctOrderVO;
import com.ict.api.vo.PageResult;
import com.ict.service.IctOrderService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author wjp
 * @since 2025-03-23
 */
@RestController
@RequestMapping("/ict-order")
public class IctOrderController {

    @Resource
    private IctOrderService orderService;

    @PostMapping
    public ApiResponse<IctOrderVO> createOrder(@RequestBody IctOrderDTO orderCreateDTO) {
        return orderService.createOrder(orderCreateDTO);
    }

    @PutMapping("/{orderId}/pay")
    public ApiResponse<String> payOrder(@PathVariable Long orderId,
                                        @RequestBody IctOrderPayDTO orderPayDTO) {
        return orderService.payOrder(orderId, orderPayDTO);
    }

    @PostMapping("/payCallBack")
    public ApiResponse payCallBack() {
        // TODO:: 查询订单明细，结算锁定的库存数量

        return ApiResponse.success();
    }

    @PutMapping("/{orderId}/cancel")
    public ApiResponse<String> cancelOrder(@PathVariable Long orderId) {
        return orderService.cancelOrder(orderId);
    }

    @GetMapping
    public ApiResponse<PageResult<IctOrderVO>> getOrderList(IctOrderDTO orderQueryDTO) {
        return orderService.getOrderList(orderQueryDTO);
    }
}

